import * as THREE from 'three'
import Experience from '../class/Experience';
import { EventEmitter } from 'events'
export default class Ground extends EventEmitter {
    constructor() {
        super();
        this.experience = new Experience();
        this.textureLoader = this.experience.textureLoader;
        this.group = new THREE.Group();

        this.canUpdate = false;
        this.experience.assets.on('ready', () => {
            this.items = this.experience.assets.items;
            this.createCircle();
            this.createCircle2();
            this.createFloor();
            this.canUpdate = true;
        })

    }

    createCircle() {
        let rotatingApertureerial = new THREE.MeshBasicMaterial({
            map: this.items['GroundCircle1'],
            transparent: true,
            opacity: 1,
            depthTest: true,
            depthWrite: false,
        });
        let rotatingApertureGeometry = new THREE.PlaneGeometry(8, 8);
        this.circle = new THREE.Mesh(rotatingApertureGeometry, rotatingApertureerial);
        this.circle.rotateX(-Math.PI / 2)
        this.circle.position.y = 0
        this.circle.scale.multiplyScalar(0.32)
        this.group.add(this.circle)
        // this.scene.add(rotatingApertureMesh);
    }
    createCircle2() {
        let rotatingApertureerial = new THREE.MeshBasicMaterial({
            map: this.items['GroundCircle2'],
            transparent: true,
            opacity: 1,
            depthTest: true,
            depthWrite: false,
        });
        let rotatingApertureGeometry = new THREE.PlaneGeometry(8, 8);
        this.circle2 = new THREE.Mesh(rotatingApertureGeometry, rotatingApertureerial);
        this.circle2.rotateX(-Math.PI / 2)
        this.circle2.position.y = 0
        this.circle2.scale.multiplyScalar(0.28)
        this.group.add(this.circle2)
    }
    createFloor() {
        let rotatingApertureerial = new THREE.MeshBasicMaterial({
            map: this.items['GroundFloor'],
            transparent: true,
            opacity: 1,
            depthTest: true,
            depthWrite: false,
        });
        let rotatingApertureGeometry = new THREE.PlaneGeometry(10, 10);
        const floor = new THREE.Mesh(rotatingApertureGeometry, rotatingApertureerial);
        floor.rotateX(-Math.PI / 2)
        floor.position.y = -0.2
        floor.scale.multiplyScalar(0.2)
        this.floor = floor;
        this.group.add(this.floor)
    }
    update() {
        if (this.canUpdate) {
            this.circle.rotation.z += 0.002
            this.circle2.rotation.z -= 0.001
        }
    }
}